package com.topscomm.gpm.script;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.gpm.GpmScript;
import com.topscomm.gpm.pojo.GpmProjectUniversalChangeEntity;
import com.topscomm.gpm.service.impl.GpmProjectUniversalChangeService;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chengengwei
 * @date 2021-08-20
 * @description: 项目变更通用脚本
 * @modify:
 */
public class GpmProjectUniversalChangeScript extends GpmScript {

    @Transactional
    public void sendMessageToPMO(ITapService service, TapEntity entity) throws Exception {
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        GpmProjectUniversalChangeService changeService= (GpmProjectUniversalChangeService) SpringUtil
                .getBean("gpmProjectUniversalChangeService");
        GpmProjectUniversalChangeEntity changeEntity = changeService.queryById(sourceid);
        changeService.sendMessageToPMO(changeEntity);
    }

    @Transactional
    public void createRecordAfterApproval(ITapService service, TapEntity entity) throws Exception {
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourcetype = ConvertUtil.convertToString(nodeins.getSourcetype());
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        GpmProjectUniversalChangeService changeService= (GpmProjectUniversalChangeService) SpringUtil
                .getBean("gpmProjectUniversalChangeService");
        changeService.createRecordAfterApproval(sourcetype, sourceid, nodeins.getExtendfield2());
    }

}
